﻿/******************************************************************************
 * Project: Processor Affinity Manager                                        *
 * File:    ManagerInstaller.cs                                               *
 * Author:  Aaron Jones                                                       *
 * Version: 1                                                                 *
 *                                                                            *
 * Description:                                                               *
 *    This file defines install/uninstall activities for the processor        *
 *    affinity manger.                                                        *
 ******************************************************************************/

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;

namespace ProcessorAffinityManager
{
    [RunInstaller(true)]
    public partial class ManagerInstaller : Installer
    {
        public ManagerInstaller()
        {
            InitializeComponent();
        }

        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);
            stateSaver.Add("TargetDirectory", Context.Parameters["TargetDirectory"].ToString());
        }

        public override void Commit(System.Collections.IDictionary savedState)
        {
            base.Commit(savedState);

            ConfigurationFile.InstallDirectory = savedState["TargetDirectory"].ToString();
            ShellExtension.Install();
        }

        protected override void OnBeforeUninstall(System.Collections.IDictionary savedState)
        {
            base.OnBeforeUninstall(savedState);

            try
            {
                ShellExtension.Remove();
                ConfigurationFile.Uninstall();
            }

            catch
            {
            }
        }
    }
}
